﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace canyinguanlixitong
{
    public partial class frmupdateroom : Form
    {
        public frmupdateroom()
        {
            InitializeComponent();
        }
        public int stuon;
        string strconn = "Data Source=.;Initial Catalog=Supermarket management system;Integrated Security=True";
        private void frmupdateroom_Load(object sender, EventArgs e)
        {
            dzh();
        }
        public void dzh() {
            SqlConnection conn = new SqlConnection(strconn);
            conn.Open();
            string sql = "Select fangName,fangJia,fangID from [Room type]";
            SqlCommand cmd = new SqlCommand(sql,conn);
           SqlDataReader reader=cmd.ExecuteReader();
           if (reader.Read())
           {
               this.tbxroomstyle.Text = reader["fangName"].ToString();
               this.tbxzuidi.Text = reader["fangJia"].ToString();
               this.tbxrongna.Text = reader["fangID"].ToString();
           }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            SqlConnection conn = new SqlConnection(strconn);
            conn.Open();
            string room = this.tbxroomstyle.Text;
            int xiaofei =Convert.ToInt32(this.tbxzuidi.Text);
            int bianhao = Convert.ToInt32(this.tbxrongna.Text);
            string sql = "update [Room type] set fangName='" + room + "',fangJia='" + xiaofei + "',fangID='"+bianhao+"' where fangID='"+stuon+"'";
            SqlCommand cmd = new SqlCommand(sql, conn);
            int i = cmd.ExecuteNonQuery();
            if (i>0)
            {
                MessageBox.Show("修改成功");
            }
            else
            {
                MessageBox.Show("修改失败");
            }
        }
    }
}
